package com.suning.app.snpaasadmin.test;

import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.suning.app.snpaasadmin.dao.ControlMachineMapper;
import com.suning.app.snpaasadmin.operation.ControlMachineDBOperation;
import com.suning.app.snpaasadmin.pojo.ControlMachine;

public class testDb {
	private static SqlSessionFactory sqlSessionFactory;
    private static Reader reader; 
    static{
        try{
            reader    = Resources.getResourceAsReader("Configuration.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    public static SqlSessionFactory getSession(){
        return sqlSessionFactory;
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SqlSession session = sqlSessionFactory.openSession();
        try {
        	ControlMachine cm = new ControlMachine();
        	cm.setActive(0);
        	cm.setHostip("10.10.105.221");
        	cm.setPassword("mhxzkhl");
        	cm.setUsername("cl");
        	ControlMachineMapper cmm=session.getMapper(ControlMachineMapper.class);
        	cmm.insert(cm);
        	System.out.print("commit");
        	session.commit();
        } finally {
        session.close();
        }
//		ControlMachineDBOperation cmo=new ControlMachineDBOperation();
//		List<ControlMachine> cmList=cmo.getListCM();
//		System.out.println("size:"+cmList.get(0).getHostip());

	}

}
